#pragma warning(disable:4267)
#pragma warning(disable:4996)
#pragma warning(disable:6031)
#pragma warning(disable:6011)

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

namespace Y190715_nqueen {
int main();

int N;
int queenPos[100];

void NQueen(int k) {
	int i;
	if (k == N) {
		for (i = 0; i < N; i++)
			printf("%d ", queenPos[i] + 1);
		printf("\n");
		return;
	}
	for (i = 0; i < N; i++) {
		int j;
		for (j = 0; j < k; j++) {
			if (queenPos[j] == i || abs(queenPos[j] - i) == abs(k - j)) {
				break;
			}
		}
		if (j == k) {
			queenPos[k] = i;
			NQueen(k + 1);
		}
	}
}



int main() {
	//scanf("%d", &N);
	N = 4;
	NQueen(0);
	return 0;
}
}

int main_Y190715_nqueen() {
	return Y190715_nqueen::main();
}
